package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2024-12-31
 * Time:20:58
 */
public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("t线程工作中！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t.start();
        //让主线程等待t线程执行结束
        //一旦调用join，主线程就会发生堵塞，此时t线程就可以趁机完成后续工作
        //一直到t执行完毕了，join才会解除堵塞，才能继续执行。
        System.out.println("join等待开始");
        t.join();
        System.out.println("join等待结束");
    }
}
